package com.hy.mydesktop.client.component.factory;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Layout;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.hy.mydesktop.client.component.meta.AccordionPanelModelEnum;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;


/**
 * 
 * <ul>
 * <li>开发作者：冬超</li>
 * <li>设计日期：2010-8-30；时间：上午09:48:15</li>
 * <li>类型名称：AccordionPanelFactory</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
public class AccordionPanelFactory {
	public static ContentPanel createContentPanel(
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {

		return configureContentPanel(gxtComponentMetaNodeModel);

	}

	/**
	 * 
	 * 
	 * @param gxtComponentMetaModel
	 * @return
	 */
	private static ContentPanel configureContentPanel(
			GxtComponentMetaNodeModel gxtComponentMetaModel) {

		ContentPanel panel = createDefaultContentPanel();
		

		if (gxtComponentMetaModel.get(AccordionPanelModelEnum.HIGHT.name()
				.toLowerCase()) != null) {
			Integer height = (Integer) gxtComponentMetaModel
					.get(AccordionPanelModelEnum.HIGHT.name().toLowerCase());
			panel.setHeight((int) height);

		}if (gxtComponentMetaModel.get(AccordionPanelModelEnum.HEIGHT.name()
				.toLowerCase()) != null) {
			Integer height = (Integer) gxtComponentMetaModel
					.get(AccordionPanelModelEnum.HEIGHT.name().toLowerCase());
			panel.setHeight((int) height);

		}if (gxtComponentMetaModel.get(AccordionPanelModelEnum.WIDTH
				.name().toLowerCase()) != null) {
			Integer width = (Integer) gxtComponentMetaModel
					.get(AccordionPanelModelEnum.WIDTH.name().toLowerCase());
			panel.setWidth((int) width);

		}  if (gxtComponentMetaModel
				.get(AccordionPanelModelEnum.ANIMCOLLAPSE.name().toLowerCase()) != null) {
			Boolean animCollapse = (Boolean) gxtComponentMetaModel
					.get(AccordionPanelModelEnum.ANIMCOLLAPSE.name()
							.toLowerCase());
			panel.setAnimCollapse(animCollapse);

		} if (gxtComponentMetaModel
				.get(AccordionPanelModelEnum.BODYSTYLENAME.name().toLowerCase()) != null) {
			String style = (String) gxtComponentMetaModel
					.get(AccordionPanelModelEnum.BODYSTYLENAME.name()
							.toLowerCase());
			panel.setBodyStyleName(style);

		}  if (gxtComponentMetaModel
				.get(AccordionPanelModelEnum.BUTTONALIGN.name().toLowerCase()) != null) {
			String alin = (String) gxtComponentMetaModel
					.get(AccordionPanelModelEnum.BUTTONALIGN.name()
							.toLowerCase());
			if (alin.equals("CENTER")) {
				panel.setButtonAlign(HorizontalAlignment.CENTER);
			} else if (alin.equals("LEFT")) {
				panel.setButtonAlign(HorizontalAlignment.LEFT);
			}

		} if (gxtComponentMetaModel
				.get(AccordionPanelModelEnum.COLLAPSIBLE.name().toLowerCase()) != null) {
			Boolean collapsible = (Boolean) gxtComponentMetaModel
					.get(AccordionPanelModelEnum.COLLAPSIBLE.name()
							.toLowerCase());
			panel.setCollapsible(collapsible);

		}if (gxtComponentMetaModel
				.get(AccordionPanelModelEnum.FRAME.name().toLowerCase()) != null) {
			Boolean frame = (Boolean) gxtComponentMetaModel
					.get(AccordionPanelModelEnum.FRAME.name()
							.toLowerCase());
			panel.setFrame(frame);

		} if (gxtComponentMetaModel
				.get(AccordionPanelModelEnum.HEADERVISIBLE.name().toLowerCase()) != null) {
			Boolean headerVisible = (Boolean) gxtComponentMetaModel
					.get(AccordionPanelModelEnum.HEADERVISIBLE.name()
							.toLowerCase());
			panel.setHeaderVisible(headerVisible);

		} if (gxtComponentMetaModel
				.get(AccordionPanelModelEnum.HEADING.name().toLowerCase()) != null) {
			String text = (String) gxtComponentMetaModel
					.get(AccordionPanelModelEnum.HEADING.name()
							.toLowerCase());
			panel.setHeading(text);

		}if (gxtComponentMetaModel
				.get(AccordionPanelModelEnum.LAYOUT.name().toLowerCase()) != null) {
			Layout layout = (Layout) gxtComponentMetaModel
					.get(AccordionPanelModelEnum.LAYOUT.name()
							.toLowerCase());
			panel.setLayout(layout);

		} if (gxtComponentMetaModel
				.get(AccordionPanelModelEnum.ICON.name().toLowerCase()) != null) {
			AbstractImagePrototype icon = (AbstractImagePrototype) gxtComponentMetaModel
					.get(AccordionPanelModelEnum.ICON.name()
							.toLowerCase());
			panel.setIcon(icon);

		}

		return panel;
	}

	private static ContentPanel createDefaultContentPanel() {

		ContentPanel panel = new ContentPanel();
		return panel;
	}
}
